home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / ABUSESRC.ZIP / AbuseSrc / abuse / src / net / dos4gw / bwtcp.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-28  |  2.4 KB  |  78 lines

  1. #include "sock.hpp"
  2. #include "dprint.hpp"
  3.  
  4. class bwip_address : public net_address
  5. {
  6.  
  7.   public :
  8.   unsigned long ip;
  9.   unsigned short port;
  10.  
  11.  
  12.   virtual protocol protocol_type() { return net_address::IP; }
  13.   virtual equal(net_address *who)
  14.   {
  15.     if (who->protocol_type()==IP && ((bwip_address *)who)->ip==ip)
  16.       return 1;
  17.     else return 0;
  18.   }
  19.   virtual int set_port(int Port)  { port=Port; }
  20.   bwip_address(unsigned long ip, unsigned short port) : port(port), ip(ip) {};
  21.   virtual void print()
  22.   {
  23.     unsigned char *c=(unsigned char *) (&ip);
  24.     dprintf("%d.%d.%d.%d",c[0],c[1],c[2],c[3]);
  25.   }
  26.   bwip_address() {} ;    
  27. } ;
  28.  
  29. class bw_tcpip_protocol : public net_protocol
  30. {
  31.   unsigned long bw_get_server_ip(char *sn);
  32.   int 
  33.   public :
  34.  
  35.   
  36.   bw_tcpip_protocol();
  37.   net_address *get_node_address(char *&server_name, int def_port, int force_port);
  38.   net_socket *connect_to_server(net_address *addr, 
  39.                 net_socket::socket_type sock_type=net_socket::SOCKET_SECURE);
  40.   net_socket *create_listen_socket(int port, net_socket::socket_type sock_type);
  41.   int select_sockets();
  42. } ;
  43.  
  44. extern bw_tcpip_protocol tcpip;
  45.  
  46. class unix_fd : public net_socket
  47. {
  48.   protected :
  49.   int fd;
  50.   public :
  51.   unix_fd(int fd) : fd(fd) { };
  52.   virtual int error()                             { return FD_ISSET(fd,&tcpip.exception_set); }
  53.   virtual int ready_to_read()                     { return FD_ISSET(fd,&tcpip.read_set); }
  54.   virtual int ready_to_write()                    
  55.   { 
  56.     struct timeval tv={0,0};     // don't wait
  57.     fd_set write_check;  
  58.     FD_ZERO(&write_check);  
  59.     FD_SET(fd,&write_check);     
  60.     select(FD_SETSIZE,NULL,&write_check,NULL,&tv);
  61.     return FD_ISSET(fd,&write_check); 
  62.   }
  63.   virtual int write(void *buf, int size)          { return ::write(fd,buf,size); }
  64.   virtual int read(void *buf, int size, net_address **addr)
  65.   {
  66.     int tr=::read(fd,buf,size);
  67.     if (addr) *addr=NULL;
  68.     return tr;
  69.   }
  70.  
  71.   virtual ~unix_fd()                            { read_unselectable();  write_unselectable(); close(fd); }
  72.   virtual void read_selectable()                   { FD_SET(fd,&tcpip.master_set); }
  73.   virtual void read_unselectable()                 { FD_CLR(fd,&tcpip.master_set); }
  74.   virtual void write_selectable()                  { FD_SET(fd,&tcpip.master_write_set); }
  75.   virtual void write_unselectable()                { FD_CLR(fd,&tcpip.master_write_set); }
  76.   int get_fd() { return fd; }
  77. } ;
  78.